home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / DYN401.ZIP / examples / exam15 / class1.d < prev    next >
Text File  |  1995-09-27  |  3KB  |  128 lines

  1.  
  2.  
  3.  
  4.  
  5. /*
  6.  *
  7.  *    This source code is CONFIDENTIAL and
  8.  *    PROPRIETARY to Algorithms Corporation. Unauthorized
  9.  *    distribution, adaptation or use    may
  10.  *    be subject to civil and    criminal penalties.
  11.  *
  12.  *    Copyright (c) 1993 Algorithms Corporation
  13.  *    3020 Liberty Hills Drive
  14.  *    Franklin, TN  37064
  15.  *
  16.  *    ALL RIGHTS RESERVED.
  17.  *
  18.  *
  19.  *
  20.  */
  21.  
  22.  
  23. defclass  Class1  {
  24.     char    iName[30];
  25.     int    iCode;
  26.     iData;
  27.   class:
  28.       int    cNumInstances;
  29. };
  30.  
  31. /*  The New method is being modified to take an additional argument (in
  32.     addition to the default 'object self') of an int.  This argument will
  33.     be used to initialize the iCode instance variable.  Although Dynace
  34.     is able to overload generic names (we could use the same generic name
  35.     with different arguments) we will rename it for clairity.  */
  36.  
  37. cmeth    gNewWithInt(int code)
  38. {
  39.     /*  Declare an object which will hold the new instance object being
  40.         created.  */
  41.     object    obj;
  42.  
  43.     /*  Declare a pointer which will point to the instance variables
  44.         associated with the new instance.  'ivType' refers to a C
  45.         structure which looks like the instance variable structure
  46.         defined in the defclass.  The name of the pointer must be 'iv'.
  47.         This is so Dynace knows how to access the instance variables
  48.         when they are refered to without the normal C iv-> construct.  */
  49.     ivType    *iv;
  50.  
  51.     /*  Increment the count as before.  */
  52.     cNumInstances++;
  53.  
  54.     /*  Create the new instance object as before, only this time put it
  55.         in obj.  */
  56.     obj = gNew(super);
  57.  
  58.     /*  Gain access to a pointer to the locally defined instance variables
  59.         associated with obj and assign it to iv.  Note that this procedure,
  60.         which is required to access instance variables, is performed
  61.         automatically on the self object on instance methods.  That is
  62.         why instance methods may directly access instance variables
  63.         associated with their self argument without the need for the
  64.         ivPtr or ivsPtr macros.  */
  65.     iv = ivPtr(obj);
  66.  
  67.     /*  Since iv is correctly updated it is now safe to directly access
  68.         the instance variables associated with obj - update iCode with
  69.         the 'code' value passed to this method.  */
  70.     iCode = code;
  71.  
  72.     /*  Since we are now through allocating and initializing the new
  73.         object, simply return it.  */ 
  74.     return obj;
  75. }
  76.  
  77. /*  Create an instance method to allow an external program to access the
  78.     value in iCode in order to test our New method.  */
  79.     
  80. imeth    int    gGetCode()
  81. {
  82.     return iCode;
  83. }
  84.  
  85. cmeth    int    gNumInstances()
  86. {
  87.     return cNumInstances;
  88. }
  89.  
  90. imeth    object    gDeepDispose, gDispose ()
  91. {
  92.     cNumInstances--;
  93.     gDispose(super self);
  94.     return NULL;
  95. }
  96.  
  97. imeth    gSetName(char *name)
  98. {
  99.     strcpy(iName, name);
  100.     return self;
  101. }
  102.  
  103. imeth    char    * gGetName : get_name ()
  104. {
  105.     return iName;
  106. }
  107.  
  108.  
  109.  
  110. /*
  111.  *
  112.  *    This source code is CONFIDENTIAL and
  113.  *    PROPRIETARY to Algorithms Corporation. Unauthorized
  114.  *    distribution, adaptation or use    may
  115.  *    be subject to civil and    criminal penalties.
  116.  *
  117.  *    Copyright (c) 1993 Algorithms Corporation
  118.  *    3020 Liberty Hills Drive
  119.  *    Franklin, TN  37064
  120.  *
  121.  *    ALL RIGHTS RESERVED.
  122.  *
  123.  *
  124.  *
  125.  */
  126.  
  127.  
  128.